package com.liziyi0914.morearmor.effect;

import com.liziyi0914.morearmor.StatusEffectManager;
import com.liziyi0914.morearmor.Utils;
import com.liziyi0914.morearmor.event.Listener;
import com.liziyi0914.morearmor.event.entity.EntityClickEvent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.FireballEntity;
import net.minecraft.item.Items;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;

import java.util.function.Predicate;

public class BlazeRodEffect extends AbstractEffect {

    public BlazeRodEffect() {
        StatusEffectManager.registerEffect(this, StatusEffects.FIRE_RESISTANCE);
    }

    @Override
    public Predicate<LivingEntity> predicateArmor() {
        return Utils.hasItemArmor(Items.BLAZE_ROD);
    }

    @Listener
    public void onInteractItem(EntityClickEvent e) {
        if(!e.isLeft())return;
        if (!Utils.hasItemArmor(Items.BLAZE_ROD).test(e.getEntity())) return;
        PlayerEntity player = (PlayerEntity) e.getEntity();
        World world = player.getEntityWorld();
        Direction direction = player.getHorizontalFacing();
        FireballEntity entity = new FireballEntity(world, player, direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ(), 1);
        entity.setPosition(player.getPos());
        world.spawnEntity(entity);
    }

}
